import * as step from '@flow-step/step-toolkit'
import process from 'process'
import {installGO} from "./install";

const ENV_NAME_GO_VERSION: string = 'CI_RUNTIME_VERSION'
const ENV_GO_PATH: string = 'GO_PATH'
async function runStep(): Promise<void> {
    const inputGOVersion: string | undefined =
        process.env[ENV_NAME_GO_VERSION]

    if (inputGOVersion == undefined) {
        throw new Error('missing env CI_RUNTIME_VERSION')
    }

    const inputGOPath: string | undefined =
        process.env[ENV_GO_PATH]
    if (inputGOPath == undefined) {
        throw new Error('missing env GO_PATH')
    }

    await installGO(inputGOVersion, inputGOPath)
}

runStep()
    .then(function () {
        step.success('run step successfully!')
    })
    .catch(function (err: Error) {
        step.error(err.message)
        process.exit(-1)
    })
